package com.org.gsc.zsqdemos.uis;

import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.support.v4.view.ViewPager;
import android.view.View;

import com.astuetz.PagerSlidingTabStrip;
import com.org.gsc.zsqdemos.R;
import com.org.gsc.zsqdemos.adapters.MypstAdapter;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by qundui on 2017/6/17.
 */

public class PstDemo extends FragmentActivity implements ViewPager.OnPageChangeListener {
    private PagerSlidingTabStrip pagerTabStrip;
    private ViewPager vp;
    private List<String> titles=new ArrayList<>();
    private MypstAdapter mypstAdapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.pst);
        vp= (ViewPager) findViewById(R.id.vp);
        pagerTabStrip= (PagerSlidingTabStrip) findViewById(R.id.ptb);
        //pstsTextAllCaps


        for(int i=0;i<10;i++){
            titles.add("第"+(i+1)+"个tab");

        }
        mypstAdapter = new MypstAdapter(getSupportFragmentManager(), titles);
        vp.setAdapter(mypstAdapter);
        pagerTabStrip.setViewPager(vp);
//        for(int i=0;i<pagerTabStrip.getTabsContainer().getChildCount();i++){
//            TextView childAt = (TextView) pagerTabStrip.getTabsContainer().getChildAt(i);
//            childAt.setTextColor(getResources().getColor(R.color.colorPrimaryDark));
//            childAt.setTextSize(30);
//
//        }
        pagerTabStrip.setTextColor(getResources().getColor(R.color.colorPrimaryDark));
        pagerTabStrip.setTextSize(40);
        String s = pagerTabStrip.getTabsContainer().getChildAt(1).toString();
        System.out.println("-------"+s);
        pagerTabStrip.setOnPageChangeListener(this);
    }



    public void addTabs(View v){
        titles.add("ABCD");
        mypstAdapter.notifyDataSetChanged();

        pagerTabStrip.notifyDataSetChanged();

    }
    public void delTabs(View view){
        titles.remove(titles.get(2));
        mypstAdapter.notifyDataSetChanged();

        pagerTabStrip.notifyDataSetChanged();
    }

    @Override
    public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
        System.out.println("onPageScrolled"+position);
    }

    @Override
    public void onPageSelected(int position) {
        System.out.println("onPageSelected"+position);
    }

    @Override
    public void onPageScrollStateChanged(int state) {
        System.out.println(" onPageScrollStateChanged"+state);
    }
}
